package com.lc.dmd.service.ds1.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.dmd.config.datasource.DynamicDataSourceContextHolder;
import com.lc.dmd.entity.Food;
import com.lc.dmd.entity.Good;
import com.lc.dmd.entity.Student;
import com.lc.dmd.entity.vo.DataVo;
import com.lc.dmd.service.ds1.StudentService;
import com.lc.dmd.mapper.StudentMapper;
import com.lc.dmd.service.ds2.FoodService;
import com.lc.dmd.service.ds3.GoodService;
import com.study.common.enums.DataSourceEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Administrator
* @description 针对表【student】的数据库操作Service实现
* @createDate 2023-09-06 15:31:28
*/
@Service
@RequiredArgsConstructor
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService{

    @Resource
    private GoodService goodService;

    @Resource
    private FoodService foodService;

    @Override
    public DataVo getAllData() {
        // 默认数据源DS1
        List<Student> students = this.list();
        // 动态切换数据源DS2
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceEnum.DS2.name());
        List<Food> foods = foodService.list();
        // 动态切换数据源DS3
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceEnum.DS3.name());
        List<Good> goods = goodService.list();
        return DataVo.builder().students(students).goods(goods).foods(foods).build();
    }
}




